<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生信息和证书关联表列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west" shiro:hasPermission="system:stuDataCer:deptTree">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa fa-sitemap"></i> 组织机构
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>


<div class="ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>学生id：</label>
                            <input type="text" name="stuId"/>
                        </li>
                        <li>
                            <label>证书id：</label>
                            <input type="text" name="cerId"/>
                        </li>
                        <li>
                            <label>审核状态：</label>
                            <select type="text" name="reviewStatus">
                                <option value="">所有</option>
                                <option value="0">未审核</option>
                                <option value="1">审核中</option>
                                <option value="2">审核通过</option>
                                <option value="3">审核未通过</option>
                            </select>
                        </li>
                        <li>
                            <label>过期情况：</label>
                            <select type="text" name="isExpired">
                                <option value="">所有</option>
                                <option value="0">过期</option>
                                <option value="1">临近过期</option>
                                <option value="2">未过期</option>
                                <option value="3">状态未知</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="reviews()" shiro:hasPermission="system:stuDataCer:edit">
                <i class="fa fa-plus"></i> 批量通过
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:stuDataCer:edit">
                <i class="fa fa-edit"></i> 审核
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:stuDataCer:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:stuDataCer:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning" onclick="downloadFiles()" shiro:hasPermission="system:stuDataCer:download">
                <i class="fa fa-download"></i> 导出文件
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
        var reviewFlag = [[${@permission.hasPermi('system:stuDataCer:review')}]];
        var removeFlag = [[${@permission.hasPermi('system:stuDataCer:remove')}]];
        var reviewInfoFlag = [[${@permission.hasPermi('system:stuDataCer:reviewInfo')}]];
        var downloadFlag = [[${@permission.hasPermi('system:stuDataCer:download')}]];
        var prefix = ctx + "system/stuDataCer";


		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
	     	// 回到顶部绑定
	    	if ($.fn.toTop !== undefined) {
	    		var opt = {
	    			win:$('.ui-layout-center'),
	    			doc:$('.ui-layout-center')
	    		};
	    		$('#scroll-up').toTop(opt);
	    	}
		    queryUserList();
		    queryDeptTree();
		});

        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                downloadFilesUrl:prefix + "/download/resources",
                modalName: "学生信息和证书关联表",
                clickToSelect: true,               // 是否启用点击选中行
                columns: [{
                    checkbox: true
                },
                {
                    field: 'studataCerId',
                    title: 'id'
                },
                {
                    field: 'stuId',
                    title: '学生id'
                },
                {
                    field: 'stuNumber',
                    title: ' 学号'
                },
                {
                    field: 'stuName',
                    title: '学生姓名'
                },
                {
                    field: 'cerId',
                    title: '证书id'
                },
                {
                    field: 'cerName',
                    title: '证书名'
                },
                {
                    field: 'reviewStatus',
                    title: '审核状态',
                    formatter: function(value, item, index) {
		                if (item.reviewStatus == '0') {
		                    return '<span class="badge badge-warning">未审核</span>';
		                }
		                else if (item.reviewStatus == '1') {
		                    return '<span class="badge badge-info">审核中</span>';
		                }
		                else if (item.reviewStatus == '2') {
		                    return '<span class="badge badge-success">审核通过</span>';
		                }
		                else if (item.reviewStatus == '3') {
		                    return '<span class="badge badge-danger">审核未通过</span>';
		                }
		            }
                }/*,
                {
                    field: 'cerDataIspublic',
                    title: '是否公开',
		        	formatter: function (value, row, index) {
		        		return publicTools(row);
		        	}
                },
                {
                    field: 'cerDeadline',
                    title: '证书过期时间'
                }*/,
                {
                    field: 'isExpired',
                    title: '是否过期',
                    formatter: function(value, item, index) {
		                if (item.isExpired == '0') {
		                    return '<span class="badge badge-danger">已过期</span>';
		                }
		                else if (item.isExpired == '1') {
		                    return '<span class="badge badge-warning">临近过期</span>';
		                }
		                else if (item.isExpired == '2') {
		                    return '<span class="badge badge-info">未过期</span>';
		                }
		                else if (item.isExpired == '3') {
		                    return '<span class="badge badge-success">状态未知</span>';
		                }
		            }
                },
                {
                    field: 'filePath',
                    title: '附件',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + reviewFlag + '" href="javascript:void(0)" onclick="review(\'' + row.studataCerId + '\')"><i class="fa fa-edit"></i>审核</a> ');
                        //actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.studataCerId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-primary btn-xs ' + downloadFlag + '" href="javascript:void(0)" onclick="downloadFile(\'' + row.studataCerId + '\'\,\'' + row.filePath + '\')" style="margin:0px 2px;"><i class="fa fa-cloud-download"></i>下载文件</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + reviewInfoFlag + '" href="javascript:void(0)" onclick="reviewInfo(\'' + row.studataCerId + '\')"><i class="fa fa-remove"></i>查看审核历史</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        /* 公开状态显示 */
		function publicTools(row) {
		    if (row.cerDataIspublic == 1) {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enable(\'' + row.studataCerId + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disable(\'' + row.studataCerId + '\')"></i> ';
    		}
		}

		/* 公开状态-公开 */
		function enable(studataCerId) {
			$.modal.confirm("确认要取消公开用户吗？", function() {
				$.operate.post(prefix + "/changeIspublic", { "studataCerId": studataCerId, "cerDataIspublic": 0 });
		    })
		}

		/* 公开状态-不公开 */
		function disable(studataCerId) {
			$.modal.confirm("确认要修改吗？", function() {
				$.operate.post(prefix + "/changeIspublic", { "studataCerId": studataCerId, "cerDataIspublic": 1 });
		    })
		}

		function reviews() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认审核通过选中的"+ rows.length + "条数据吗?", function() {
                var data = { "studataCerIds": rows.join() };
                $.operate.submit( prefix + "/reviews", "post", "json", data);
                <!--window.location.href = prefix + "/reviews?studataCerIds=" + rows;-->
            });
		}

		function downloadFile(studataCerId,value){
            if(value == null || value == ""){
                $.modal.alert("文件未找到或者文件不存在！");
                return false;
            }else{
                window.location.href = prefix + "/download/resource?studataCerId=" + studataCerId;
            }
        }

        function downloadFiles() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要下载选中的"+ rows.length + "条数据吗?", function() {
                var url = table.options.downloadFiles;
                window.location.href = prefix + "/download/resources?studataCerIds=" + rows;
            });
        }

		function review(studataCerId) {
			var url = prefix + "/review/" + studataCerId;
			$.modal.open("审核", url);
		}

        function reviewInfo(studataCerId) {
			var url = prefix + "/reviewInfo/" + studataCerId;
			$.modal.open("审核历史", url);
		}

		function queryDeptTree()
		{
			var url = ctx + "system/certificate/deptTreeData";
			var options = {
		        url: url,
		        expandLevel: 2,
		        onClick : zOnClick
		    };
			$.tree.init(options);

			function zOnClick(event, treeId, treeNode) {
				$("#deptId").val(treeNode.id);
				$("#parentId").val(treeNode.pId);
				$.table.search();
			}
		}

		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});

		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});

		$('#btnRefresh').click(function() {
			queryDeptTree();
		});
    </script>
</body>
</html>
